from django.db import models


def stuff_directory_path(instance, filename):
    return 'media/user/avatar/{}/{}'.format(instance.id, filename)


TYPE = [
    (1, '武器'),
    (2, '护甲'),
    (3, '药品'),
    (4, '消耗品'),
    (5, '任务物品'),
]
QUALITY = [
    (1, '普通'),
    (2, '精良'),
    (3, '稀有'),
    (4, '完美'),
    (5, '史诗'),
    (6, '传奇'),
]


class Stuff(models.Model):
    name = models.CharField(max_length=1024, verbose_name="物品名称")
    icon = models.ImageField(upload_to=stuff_directory_path, verbose_name='物品图标')
    illustrate = models.TextField(verbose_name='说明')
    level = models.SmallIntegerField(default=1, verbose_name='最低使用等级')
    IS_TRADEBLE = [
        (1, '可交易'),
        (0, '不可交易'),
    ]
    is_tradable = models.SmallIntegerField(default=1, choices=IS_TRADEBLE, verbose_name='是否可交易')
    weight = models.SmallIntegerField(default=1, verbose_name='负重')

    class Meta:
        verbose_name = '物品'
        ordering = ['name']
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Weapon(Stuff):
    type = models.SmallIntegerField(default=1, choices=TYPE, editable=False, verbose_name='物品类型')
    quality = models.SmallIntegerField(choices=QUALITY, default=1, verbose_name='物品品质')
    enhancement = models.SmallIntegerField(default=0, verbose_name='基础强化等级')
    min_attack = models.SmallIntegerField(default=2, verbose_name='最小攻击')
    max_attack = models.SmallIntegerField(default=5, verbose_name='最大攻击')
    agility = models.SmallIntegerField(default=1, verbose_name='敏捷')
    slot = models.SmallIntegerField(default=0, verbose_name='宝石插槽')
    durability = models.SmallIntegerField(default=350, verbose_name='耐久')

    class Meta:
        verbose_name = '武器'
        ordering = ['name']
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Armor(Stuff):
    type = models.SmallIntegerField(default=2, choices=TYPE, editable=False, verbose_name='物品类型')
    quality = models.SmallIntegerField(choices=QUALITY, default=1, verbose_name='物品品质')
    enhancement = models.SmallIntegerField(default=0, verbose_name='基础强化等级')
    defense = models.SmallIntegerField(default=1, verbose_name='防御值')
    agility = models.SmallIntegerField(default=1, verbose_name='敏捷')
    slot = models.SmallIntegerField(default=0, verbose_name='宝石插槽')
    lucky = models.SmallIntegerField(default=1, verbose_name='幸运一击')
    durability = models.SmallIntegerField(default=350, verbose_name='耐久')
    poison_resistance = models.SmallIntegerField(default=0, verbose_name='毒药抗性')

    class Meta:
        verbose_name = '护甲'
        ordering = ['name']
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Consumable(Stuff):
    class Meta:
        verbose_name = '消耗品'
        ordering = ['name']
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name
